import os
from building import *
import rtconfig

cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp') + Glob('avr/*.c')
inc = [cwd]

CXXFLAGS = ''
LOCAL_CCFLAGS = ''
LOCAL_CFLAGS = ''
LOCAL_CXXFLAGS = ''

if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'armclang': # GCC or Keil AC6
    LOCAL_CFLAGS += ' -std=gnu99' # enable GNU extension. Cannot use -std=c99, some toolchain like RISC-V GCC doesn't support 'asm' key word
    LOCAL_CXXFLAGS += ' -std=c++11' # support C++11, like non-static data member initializers
elif rtconfig.PLATFORM == 'armcc': # Keil AC5
    CXXFLAGS = ' --gnu --c99' # enable global C99 and GNU extension support for the whole project
    LOCAL_CCFLAGS += ' --gnu -g -W'
    LOCAL_CFLAGS += ' --c99' # cannot use --c99 symbol for C++ files, pertically in Keil
    LOCAL_CXXFLAGS += ' --cpp11' # support C++11

if GetDepend(['RTDUINO_TINY_MODE']):
    SrcRemove(src, ['Tone.cpp', 'WInterrupts.c', 'wiring_analog.c', 'wiring_digital.c', 'wiring_pulse.c', 'wiring_shift.c'])

group = DefineGroup('RTduino', src,
                     depend = ['PKG_USING_RTDUINO'],
                     CPPPATH = inc,
                     CPPDEFINES = ['ARDUINO=10819', 'ARDUINO_ARCH_RTTHREAD'],
                     CXXFLAGS = CXXFLAGS,
                     LOCAL_CCFLAGS = LOCAL_CCFLAGS,
                     LOCAL_CFLAGS = LOCAL_CFLAGS,
                     LOCAL_CXXFLAGS = LOCAL_CXXFLAGS)

list = os.listdir(cwd)
for item in list:
    if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
        group = group + SConscript(os.path.join(item, 'SConscript'))

Return('group')
